package com.exam.action;

import java.io.ByteArrayInputStream;

import com.exam.util.RandomCodeUtil;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 验证码生成Action
 * 
 * @author MuLing
 * 
 */
public class RandomCodeAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	private ByteArrayInputStream inputStream;

	public String execute() throws Exception {
		RandomCodeUtil rdnu = RandomCodeUtil.Instance();// 取得随机验证码产生类的对象
		this.setInputStream(rdnu.getImage());// 取得带有随机字符串的图片
		ActionContext.getContext().getSession().put("randomCode",
				rdnu.getString());// 取得随机字符串放入HttpSession
		return SUCCESS;
	}

	public void setInputStream(ByteArrayInputStream inputStream) {
		this.inputStream = inputStream;
	}

	public ByteArrayInputStream getInputStream() {
		return inputStream;
	}
}
